﻿@using PagedList;
@model PagedList.IPagedList<TaoNiuOA.Models.Apply>
@{
    ViewBag.Title = "我的申请";
    Layout = "~/Views/Shared/_AdminLayout.cshtml";
}
<script type="text/javascript">
    function showStatus(obj) {
        switch (obj) {
            case 0:
                document.write("拒绝");
                break;
            case 1:
                document.write("同意");
                break;
            default:
                document.write("审批中");
                break;
        }
    }
</script>
<fieldset>
    <legend>我的申请</legend>
    <p>
        @Html.ActionLink("新建申请", "MyApplyNew")
    </p>
    <div>
        <ul>
            <li><a href="?mod=all">所有申请(@ViewData["allcount"])</a></li>
            <li><a href="?mod=agree">已同意的(@ViewData["agreecount"])</a></li>
            <li><a href="?mod=approve">审批中的(@ViewData["approvecount"])</a></li>
            <li><a href="?mod=refuse">已拒绝的(@ViewData["refusecount"])</a></li>
        </ul>
    </div>
    <div id="myapplytip" style="text-align: center; color: Red; font-size: larger;">
    </div>
    <table>
        <tr>
            <th>
                申请人
            </th>
            <th>
                标题
            </th>
            <th>
                申请时间
            </th>
            <th>
                类型
            </th>
            <th>
                开始时间
            </th>
            <th>
                结束时间
            </th>
            <th>
                状态
            </th>
            <th>
                审批者
            </th>
            <th>
                操作
            </th>
        </tr>
        @foreach (var item in Model)
        {
            <tr>
                <td>
                    @item.GetUser().GetUserInfo().Name
                </td>
                <td>
                    @Html.DisplayFor(modelItem => item.Title)
                </td>
                <td>
                    @item.ApplyTime
                </td>
                <td>
                    @Html.DisplayFor(modelItem => item.GetApplyType().TypeName)
                </td>
                <td>
                    @Html.DisplayFor(modelItem => item.StartTime)
                </td>
                <td>
                    @Html.DisplayFor(modelItem => item.EndTime)
                </td>
                <td>
                    <script>showStatus(@item.Status);</script>
                </td>
                <td>
                    @item.GetApprover().GetUserInfo().Name
                </td>
                <td>
                    @Html.ActionLink("详细", "MyApplyDetails", new { id = item.ApplyID })
                    | <a href="javascript:editMyApply(@item.ApplyID)">编辑</a> | <a href="javascript:delMyApply(@item.ApplyID)">
                        删除</a>
                </td>
            </tr>
        }
    </table>
    <div style="width: auto; height: 30px; margin-top: 20px; text-align: center;">
        @(Model.PageCount < Model.PageNumber ? 0 : Model.PageNumber)
        / @Model.PageCount
        &nbsp;
        @if (Model.HasPreviousPage)
        {
            @Html.ActionLink("首页", "MyApply", new { mod = ViewData["mod"], page = 1, currentFilter = ViewBag.CurrentFilter })
            @Html.Raw("&nbsp;");
            @Html.ActionLink("上一页", "MyApply", new { mod = ViewData["mod"], page = Model.PageNumber - 1, currentFilter = ViewBag.CurrentFilter })
        }
        else
        {
            @:首页
        @Html.Raw("&nbsp;");
            @:上一页
                         }
        &nbsp;
        @if (Model.HasNextPage)
        {
            @Html.ActionLink("下一页 ", "MyApply", new { mod = ViewData["mod"], page = Model.PageNumber + 1, currentFilter = ViewBag.CurrentFilter })
            @Html.Raw("&nbsp;");
            @Html.ActionLink("尾页", "MyApply", new { mod = ViewData["mod"], page = Model.PageCount, currentFilter = ViewBag.CurrentFilter })
        }
        else
        {
            @:下一页
        @Html.Raw("&nbsp;")
            @:尾页
                       }
    </div>
</fieldset>
<script type="text/javascript">
    function delMyApply(obj) {
        if (confirm("您确定要删除吗?")) {
            $.post("DelMyApply/" + obj, function (data) {
                if (data == "删除成功")
                    window.location.reload();
                alert(data);
            });
        }
    }
    function editMyApply(obj) {
        $.post("isCanEditApply/" + obj, function (data) {
            if (data == "ok")
                window.location.href = "MyApplyEdit/" + obj;
            else {
                alert(data);
            }
        });
    }
</script>
<script src="../../Scripts/jquery-1.5.1.min.js" type="text/javascript"></script>
